<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>安全责任人管理</title>
<script src="${ctx}/static/selectWin/staffinfoSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script type="text/javascript">
	var SelectedUser;
	var $grid;
	var $staffinoSelector;
	$(function() {
		alert("");
		$grid = $("#grid").datagrid($.extend(datagridOption, {
			toolbar : "#toolbar",
			method : "get",
			singleSelect : true,
			pagination : true,
			url : "${ctx}/stu/safety/safeResponse/dataGrid",
			fitColumns : false,
			columns : [ [ {
				field : 'ck',
				checkbox : true
			}, {
				field : 'trueName',
				title : '姓名',
				width : 80,
				sortable : true
			}, {
				field : 'postName',
				title : '职务',
				width : 80,
				sortable : true
			}, {
				field : 'phone',
				title : '联系电话',
				width : 80,
				
				sortable : true
			}, {
				field : 'scope',
				title : '责任范围',
				width : 100,
				sortable : true
			} ] ],
			onClickRow : function(rowIndex, rowData) {
				selectTableRow = rowData;
			}										
		}));
		$grid.datagrid('enableFilter', [ {
			field : 'trueName',
			type : 'text',
			searchField : 'trueName'
		}, {
			field : 'postName',
			type : 'text',
			searchField : 'postName'
		}, {
			field : 'phone',
			type : 'text',
			searchField : 'phone'
		}, {
			field : 'scope',
			type : 'text',
			searchField : 'scope'
		} ]);
		$("#excelExport").click(function() {
			var url = "${ctx}/stu/safety/safeResponse/excelExport?" + $.param($("#grid").datagrid('options').queryParams);
			if ($("#grid").datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($("#grid").datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/stu/safety/safeResponse/multiDelete");
		});

		$("#staffinfoSelector").click(function() {
			$.easyui.showGridSelector($.extend(staffinfoSelectOpts, {
				onEnter : function(val) {
					if (val) {
				
						$("#trueName").val(val.trueName);
						$("#postName").val(val.postName);
						$("#phone").val(val.phone);
						$("#scope").val(val.scope)
					}
				}
			}));
		});
	});

	function fun_user_add() {
		$("#dlg").dialog("open").dialog("setTitle", "新增用户");
		$("#fm").form("clear");
		$("#pass").val("123456");
	}
	
	function fun_user_edit() {
		var rowData = $("#grid").datagrid("getSelected");
		if (rowData == null) {
			showAlert("您未选择任何记录!");
		} else {
			$("#dlg").dialog("open").dialog("setTitle", "编辑用户--[" + rowData.trueName + "]");
			$("#fm").form("clear");
			if (rowData.staffinfo) {
				$("#fm").form("load", $.extend(rowData, {
					postName : rowData ? rowData.postName : "",
					phone : rowData ? rowData.phone : "",
					scope : rowData ? rowData.scope : ""
	
				}));
			} else {
				$("#fm").form("load", rowData);
			}
			
		}
	}
	function fun_user_save() {
		$("#fm").form("submit", {
			url : "${ctx}/stu/safety/safeResponse/update",
			success : function(data) {
				if (data.success) {
					$("#dlg").dialog("close");
					$("#grid").datagrid("load");
				}
				showInfo(data.msg);
			}
		});
	}
	
</script>
</head>
<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true">
		</table>
		<div id="toolbar" class="row">
			<div class="col-md-12">
			<!-- 功能按钮 -->
			<shiro:hasPermission name="user:update">
			<button id="btn-add" type="button" class="btn btn-primary" onclick="fun_user_add()">
					<span class="glyphicon glyphicon-plus"></span> 新增用户
				</button>
				<button id="btn-edit" type="button" class="btn btn-primary" onclick="fun_user_edit()">
					<span class="glyphicon glyphicon-pencil"></span> 修改
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="user:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="user:export">
			<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
			</shiro:hasPermission>
			</div>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog" style="width: 670px; height: 365px; padding: 10px 20px" 
		data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
		<form id="fm" method="post">
			<input id="id" name="id" type="hidden" /> 
			<table id="tbl">
				<tr>
					<td><label>登陆账号:</label></td>
					<td><input id="trueName" name="trueName" class="easyui-validatebox" data-options="required:true" readonly="readonly" /></td>
					<td><label>职务:</label></td>
					<td><input id="postName" name="postName"  class="easyui-validatebox" readonly="readonly" /></td>
				</tr>
				<tr>
					<td><label>电话:</label></td>
					<td><input id="phone" name="phone" class="easyui-numberbox" data-options="required:true" readonly="readonly" /></td>
			     </tr>	
			     <tr>
			 		<td><label>责任范围:</label></td>
					<td><input name="scope"  id="scope" class="easyui-textbox" data-options="multiline:true"  style="width:100px;height:80px"/>
		  	         <td><label> 备注:</label></td>
					<td><input name="remark"  id="remark" class="easyui-textbox" data-options="multiline:true"  style="width:100px;height:80px"/>
		  	    </tr>
			</table>
		</form>
		
		<div id="dlg-btn">

				<button id="add" type="button" class="btn btn-primary" onclick="fun_user_save();">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
	</div>
</body>
</html>
